[grpcio] Fix AioRpcError.trailing_metadata and Metadata iteration#15899
Merged
srittau merged 1 commit intoJun 13, 2026
Merged
Conversation
2ce78ec to
576278d
Compare
Contributor
Author
|
I originally included a regression test, but I saw the comments made on other PRs around performance considerations of adding tests so I opted to remove it. See it below for reference: # Regression test for the AioRpcError.trailing_metadata() override: it must
# return the async grpc.aio.Metadata (iterating as (key, value) tuples), not the
# synchronous tuple[_Metadatum, ...] inherited from grpc.RpcError.
def check_aio_rpc_error_trailing_metadata(error: grpc.aio.AioRpcError) -> None:
assert_type(error.trailing_metadata(), grpc.aio.Metadata)
for key, value in error.trailing_metadata():
assert_type(key, str)
assert_type(value, grpc.aio._MetadataValue) |
5b06964 to
af81a5e
Compare
This comment has been minimized.
This comment has been minimized.
srittau
requested changes
Jun 13, 2026
88fdf54 to
b965c6c
Compare
b965c6c to
6819c1f
Compare
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
approved these changes
Jun 13, 2026
srittau
left a comment
Collaborator
There was a problem hiding this comment.
Thanks! For future reference: Please don't squash commits as it makes it harder to review. We squash on merge anyway.
Contributor
Author
|
Apologies, will do 👍. Thanks for merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I encountered a typing issue when using
grpc.aioand figured I would write a PR to solve it at source.Two related fixes to the async (
grpc.aio) metadata types:AioRpcError.trailing_metadata()inherited the synchronousRpcError.trailing_metadata() -> tuple[_Metadatum, ...], but at runtime returns agrpc.aio.Metadata(
_call.py).Added the override.
grpc.aio.Metadatawas modelled as aMapping, but the runtime class is aCollectionthat iterates(key, value)tuples(
_metadata.py).Re-based on
Collection[_MetadatumType]with an item-yielding__iter__; keyedaccess (
m[key],m.get(...)) is unchanged.Together these let
for key, value in err.trailing_metadata()type-check — itpreviously errored with "
_Metadatumis not iterable".Please let me know if I've overlooked something in the contribution process.